package cc.fs.myproject;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cc.fs.myproject.NetworkRetrofit.APIClient;
import cc.fs.myproject.NetworkRetrofit.GitBean;
import cc.fs.myproject.RetrofitUtil.ApiFactory;
import cc.fs.myproject.RetrofitUtil.model.WeatherInfo;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class RetrofitActivity extends BaseActivity {

    @InjectView(R.id.getWeather)
    Button getWeather;

    public static void start(Context context) {
        Intent intent = new Intent(context, RetrofitActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retrofit);
        ButterKnife.inject(this);

        getWeather.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Log.e("---->","开始网络任务");
//                APIClient.creater( new Callback<List<GitBean>>() {
//                    @Override
//                    public void success(List<GitBean> gitBeansList, Response response) {
//                        Toast.makeText(getApplicationContext(), "获得", Toast.LENGTH_SHORT).show();
//                        Log.e("--成功--->", gitBeansList.size()+" \n "+gitBeansList.toString());
//                    }
//
//                    @Override
//                    public void failure(RetrofitError retrofitError) {
//                        Log.e("---失败-->", retrofitError.toString());
//                    }
//                });
                ApiFactory.getInstance(_this).getWeather(new Callback<WeatherInfo>() {
                    @Override
                    public void success(WeatherInfo weatherInfo, Response response) {
                        Log.e("====>",weatherInfo.toString());
                    }

                    @Override
                    public void failure(RetrofitError retrofitError) {

                    }
                });
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_retrofit, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
